package cn.xxm.strategy.pay.i18n.response;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

public class FFResponseModel<T> implements Serializable {

    private static final long serialVersionUID = -2215304260629038881L;
    // 状态码
    private String code;
    // 业务提示语
    private String msg;
    // 数据对象
    private T data;


	public FFResponseModel() {
        this.code = Errcode.SUCCESS_CODE;
        this.msg = Errcode.SUCCESS_MSG;
    }

/*   public FFResponseModel(String code) {
        this.code = code;
        this.msg = Errcode.code2MsgMap.get(code);
    }
*/
    public FFResponseModel(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = (T) new Object();
    }

    public FFResponseModel(T data) {
        this.code = Errcode.SUCCESS_CODE;
        this.msg = Errcode.SUCCESS_MSG;
        if(data != null) {
        	this.data = data;
        } else {
        	this.data = (T) new Object();
        }
    }

    public FFResponseModel(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        if(data != null) {
        	this.data = data;
        } else {
        	this.data = (T) new Object();
        }
    }

    public String toString() {
        return JSONObject.toJSONString(this);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public static <T> FFResponseModel<T> buildFFResponseModel(String code, String msg, T data) {
    	FFResponseModel<T> response = new FFResponseModel<T>();
    	response.setCode(code);
    	response.setMsg(msg);
    	response.setData(data);
		return response;
	}
    public static <T> FFResponseModel<T> buildSuccess() {
    	return buildFFResponseModel(Errcode.SUCCESS_CODE, Errcode.SUCCESS_MSG, null);
    }

    public static <T> FFResponseModel<T> buildFail() {
    	return buildFFResponseModel(Errcode.FAILED_CODE, Errcode.FAILED_MSG, null);
    }

    
	public static <T> FFResponseModel<T> buildSuccess(T data) {
		return buildFFResponseModel(Errcode.SUCCESS_CODE, Errcode.SUCCESS_MSG, data);
	}
}
